//
//  LineTransferInputTableViewCell.m
//  JxCarios
//
//  Created by xcq on 15/2/27.
//  Copyright (c) 2015年 xiongchuanqi. All rights reserved.
//

#import "LineTransferInputTableViewCell.h"
#define Point @"1234567890/n"


@implementation LineTransferInputTableViewCell

- (void)awakeFromNib {
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldShouldReturn) name:@"getOilCard" object:nil];

}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    if(textField.tag == 300){

    }else{
        NSCharacterSet *cs;
        cs = [[NSCharacterSet characterSetWithCharactersInString:Point]invertedSet];
        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
        BOOL canChange = [string isEqualToString:filtered];
        return canChange;
    }
 
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self endEditing:YES];
    return YES;
}


- (void)textFieldShouldReturn {
    UIViewController *viewC = (UIViewController *)_target;
    [viewC.view endEditing:YES];
    NSDictionary *param = nil;
    if (_nameText.text.length > 0 && _oilCardNum.text.length > 0) {
        param = [NSDictionary dictionaryWithObjectsAndKeys:_nameText.text,@"name",_oilCardNum.text,@"oilCard", nil];
    }else if(_nameText.text.length > 0){
        param = [NSDictionary dictionaryWithObjectsAndKeys:_nameText.text,@"name",nil];
    }else if(_oilCardNum.text.length > 0){
        param = [NSDictionary dictionaryWithObjectsAndKeys:_oilCardNum.text,@"oilCard",nil];
    }else {
     }
    if (_target) {
        [_target performSelector:_action withObject:param];
    }
 }

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
